#include "FSM.h"
//-------------------------------------------------------------
FSM::FSM()
{
}
//-------------------------------------------------------------
FSM::~FSM()
{
}
//-------------------------------------------------------------
void FSM::registerTransition(State* kOriginState, Event* kEvent, State* kDestState)
{
	StateEventPair p;
	p.first = kOriginState;
	p.second = kEvent;

	itTransitionMap it = m_kTransitions.find(p);
	if (it == m_kTransitions.end())
		m_kTransitions.insert(TransitionPair(p, kDestState));
	else
		it->second = kDestState;
}
//-------------------------------------------------------------
void FSM::doEvent(Event* kEvent)
{
	itTransitionMap it = m_kTransitions.find(StateEventPair(m_kCurrentState, kEvent));
	if (it != m_kTransitions.end())
	{
		m_kCurrentState->onExit();
		m_kCurrentState = it->second;
		m_kCurrentState->onEntry();
	}
}
//-------------------------------------------------------------
void FSM::update()
{
	m_kCurrentState->onUpdate();
}
//-------------------------------------------------------------

